package com.acwing.lc.part1;

import java.util.HashSet;
import java.util.Set;

/**
 * @author rkc
 * @date 2022/9/5 10:01
 */
public class LC3无重复字符的最长子串 {

    private Set<Character> set = new HashSet<>();

    public int lengthOfLongestSubstring(String s) {
        int ans = 0;
        for (int i = 0, j = 0; i < s.length(); i++) {
            while (set.contains(s.charAt(i))) set.remove(s.charAt(j++));
            ans = Math.max(ans, i - j + 1);
            set.add(s.charAt(i));
        }
        return ans;
    }
}
